package com.zbkj.business.sys.receive;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 用户领卡流程表
 * @create: 2025-04-07 12:00:24
 **/
@Service("examReceive")
@Slf4j
public class ExamReceiveService{

    @Resource
    ExamReceiveDao examReceiveDao;

    /**
     * 添加用户领卡流程表,获取id数据
     *
     * @param cdoRequest - id:编号
     *                   - receive_name:姓名
     *                   - receive_phone:手机号
     *                   - receive_idCard:身份证号
     *                   - receive_town:城市
     *                   - receive_address:住址
     *                   - receive_card:标记（0：已开卡；1未开卡）
     *                   - receive_card_courier:开卡快递号
     *                   - receive_card_phone:开卡手机号
     *                   - receive_circumference:备注
     *                   - created_at:添加时间
     *                   - updated_at:更新时间
     * @return
     * @author 
     * @create: 2025-04-07 12:00:24
     */
    @OpenApi
    public Return addExamReceive(CDO cdoRequest) {
        examReceiveDao.addExamReceive(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新用户领卡流程表数据
     *
     * @param cdoRequest - id:编号
     *                   - receive_name:姓名
     *                   - receive_phone:手机号
     *                   - receive_idCard:身份证号
     *                   - receive_town:城市
     *                   - receive_address:住址
     *                   - receive_card:标记（0：已开卡；1未开卡）
     *                   - receive_card_courier:开卡快递号
     *                   - receive_card_phone:开卡手机号
     *                   - receive_circumference:备注
     *                   - created_at:添加时间
     *                   - updated_at:更新时间
     * @return
     * @author 
     * @create: 2025-04-07 12:00:24
     */
    @OpenApi
    public Return updateExamReceiveById(CDO cdoRequest) {
        int affectedRows = examReceiveDao.updateExamReceiveById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除用户领卡流程表数据
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-04-07 12:00:24
     */
    //@OpenApi
    public Return deleteExamReceiveById(CDO cdoRequest){
        int affectedRows = examReceiveDao.deleteExamReceiveById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除用户领卡流程表数据
     *
     * @param cdoRequest
     * @return
     * @author 
     * @create: 2025-04-07 12:00:24
     */
    //@OpenApi
    public Return deleteExamReceive(CDO cdoRequest) {
        int affectedRows = examReceiveDao.deleteExamReceive(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取用户领卡流程表数据
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-04-07 12:00:24
     */
    @OpenApi
    public Return getExamReceiveById(CDO cdoRequest) {
        CDO cdoMapperResult = examReceiveDao.getExamReceiveById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取用户领卡流程表数据
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-04-07 12:00:24
     */
    @OpenApi
    public Return getExamReceive(CDO cdoRequest) {
        CDO cdoMapperResult = examReceiveDao.getExamReceive(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取用户领卡流程表数据列表
     *
     * @param cdoRequest
     * @return
     * @author 
     * @create: 2025-04-07 12:00:24
     */
    @OpenApi
    public Return getExamReceiveList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = examReceiveDao.getExamReceiveList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = examReceiveDao.getExamReceiveListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取用户领卡流程表数据列表
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-04-07 12:00:24
     */
    @OpenApi
    public Return getExamReceiveListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = examReceiveDao.getExamReceiveListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = examReceiveDao.getExamReceiveListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
